<?php
namespace Home\Controller;
defined('IN_ECTOUCH') or die('Deny Access');
require_once('WxPayDataBase.class.php');
class WxPayResults extends WxPayDataBase
{
  /**
   * 
   * 检测签名
   */
  public function CheckSign()
  {
    if(!$this->IsSignSet()){
      return true;//修改
    }
    
    $sign = $this->MakeSign();
    if($this->GetSign() == $sign){
      return true;
    }
    else
    {
      //签名错误，就清空签名
      $this->values['sign']='';
      $this->values['return_code']='Fail';//判断签名失败
      $this->values['return_msg']='fail签名验证失败！';//判断签名失败
      return false;
    }

    // throw new WxPayException("签名错误！");
  }
  
  /**
   * 
   * 使用数组初始化
   * @param array $array
   */
  public function FromArray($array)
  {
    $this->values = $array;
  }
  
  /**
   * 
   * 使用数组初始化对象
   * @param array $array
   * @param 是否检测签名 $noCheckSign
   */
  public static function InitFromArray($array, $noCheckSign = false)
  {
    $obj = new self();
    $obj->FromArray($array);
    if($noCheckSign == false){
      $obj->CheckSign();
    }
        return $obj;
  }
  
    /**
     * 将xml转为array
     * @param string $xml
     * @throws WxPayException
     */
  public static function Init($xml)
  { 
    $obj = new self();
    $obj->FromXml($xml);
    $obj->CheckSign();
    
    return $obj->GetValues();

  }
      /**
     * 将xml转为array
     * @param string $xml
     * @throws WxPayException
     */
  public static function InitArray($array)
  { 
    $obj = new self();
    $obj->FromArray($array);
    $obj->CheckSign();
    
    return $obj->GetValues();

  }

}

